package cn.lanqiao.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import cn.lanqiao.entity.Course;


public class TeacherAddCourseFrm extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private TeacherCourse teacherCourse;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			TeacherAddCourseFrm dialog = new TeacherAddCourseFrm();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	TeacherAddCourseFrm(TeacherCourse teacherCourse){
		this();
		this.teacherCourse = teacherCourse;
	}
	/**
	 * Create the dialog.
	 */
	public TeacherAddCourseFrm() {
		setTitle("课程信息添加");
		setBounds(100, 100, 645, 410);
		TeacherAddCourseFrm.this.setLocationRelativeTo(null);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		JButton btnNewButton = new JButton("课程编号");
		btnNewButton.setBounds(30, 39, 113, 27);
		contentPanel.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("课程名称");
		btnNewButton_1.setBounds(30, 108, 113, 27);
		contentPanel.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("任课教师");
		btnNewButton_2.setBounds(30, 182, 113, 27);
		contentPanel.add(btnNewButton_2);
		
		JButton btnNewButton_3 = new JButton("考试时间");
		btnNewButton_3.setBounds(30, 262, 113, 27);
		contentPanel.add(btnNewButton_3);
		
		textField = new JTextField();
		textField.setBounds(329, 40, 86, 24);
		contentPanel.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setBounds(329, 123, 86, 24);
		contentPanel.add(textField_1);
		textField_1.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setBounds(329, 193, 86, 24);
		contentPanel.add(textField_2);
		textField_2.setColumns(10);
		
		textField_3 = new JTextField();
		textField_3.setBounds(329, 273, 86, 24);
		contentPanel.add(textField_3);
		textField_3.setColumns(10);
		
		JButton btnNewButton_4 = new JButton("确认添加");
		btnNewButton_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 添加学生信息
				String cid=textField.getText();
				String cname=textField_1.getText();
				String cteacher=textField_2.getText();
				String cexam=textField_3.getText();
				//封装成一个新的对象
				Course course=new Course(cid,cname,cteacher,cexam);
				//调用业务层
				cn.lanqiao.service.CourseService service=new cn.lanqiao.service.impl.CourseServiceImpl();
				service.addCourse(course);
				//关闭
				TeacherAddCourseFrm.this.dispose();
				//刷新
				teacherCourse.bindToJTable();
			}
		});
		btnNewButton_4.setBounds(465, 108, 120, 61);
		contentPanel.add(btnNewButton_4);
		
		JButton btnNewButton_5 = new JButton("取消");
		btnNewButton_5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				TeacherAddCourseFrm.this.dispose();
			}
		});
		btnNewButton_5.setBounds(465, 222, 120, 67);
		contentPanel.add(btnNewButton_5);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
		}
	}
	
}
